package mpYoga

import (
	"duoke/model"
	"duoke/model/yogaModel"
	"duoke/service/common"
	yogaService "duoke/service/yoga"
	"duoke/utils/response"
	"duoke/utils/valid"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"
)

var Teacher = new(teacherCtl)

type teacherCtl struct{}

func (ctl *teacherCtl) List(c *gin.Context) {
	var req model.ReqListV2
	if err := c.ShouldBindJSON(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	var list []yogaModel.ReqTeacher
	where := fmt.Sprintf("venue_id=%d", req.FromId)
	count, err := common.Tales.Infos(c, &req, where, "*").Table("yoga_teacher").
		FindAndCount(&list)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", gin.H{"total": count, "list": list})
}
func (ctl *teacherCtl) PrivateClasses(c *gin.Context) {
	var req yogaModel.SearchGroupClass
	if err := c.ShouldBindJSON(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	list, count, err := yogaService.Teacher.PrivateClasses(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", gin.H{"total": count, "list": list})
}
func (ctl *teacherCtl) Info(c *gin.Context) {
	var req model.ReqId
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	info, err := yogaService.Teacher.Info(c, req.Id)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", info)
}
func (ctl *teacherCtl) CourseDetails(c *gin.Context) {
	var req model.ReqListV2
	if err := c.ShouldBind(&req); err != nil {
		response.Error(c, valid.GetError(err.(validator.ValidationErrors), req), nil)
		return
	}
	list, err := yogaService.Teacher.CourseDetails(c, &req)
	if err != nil {
		response.Error(c, err.Error(), nil)
		return
	}
	response.Success(c, "success", list)
}
